<template>
  <div class="head-container">
    <!-- 搜索 -->
    <el-input v-model="query.planName" clearable placeholder="请输入计划名称" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
    <el-select v-model="query.templateId" clearable placeholder="请选择巡检内容" style="width: 200px" class="filter-item" @change="toQuery">
      <el-option v-for="(itemobject,index) in inspectionTemplate" :key="index" :label="itemobject.templateName" :value="itemobject.id" />
    </el-select>
    <el-select v-model="query.state" clearable placeholder="请选择计划状态" class="filter-item" style="width: 200px" @change="toQuery">
      <el-option v-for="item in stateOptions" :key="item.id" :label="item.name" :value="item.id" />
    </el-select>
    <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
    <!-- 新增 -->
    <div style="display: inline-block;margin: 0px 2px;">
      <el-button
        v-permission="['ADMIN','INSPECTIONPLAN_ALL','INSPECTIONPLAN_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="add"
      >
        新增
      </el-button>
      <eForm ref="form" :is-add="true" :is-view="false" />
    </div>
  </div>
</template>

<script>
import eForm from './form'
import { INSPECTION_TYPES } from '@/constants/consts'
import { queryTemplate } from '@/api/inspectionTemplate'
export default {
  components: { eForm },
  props: {
    query: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      inspectionType: INSPECTION_TYPES,
      inspectionTemplate: [],
      stateOptions: [
        { id: 1, name: '启动' },
        { id: 0, name: '暂停' }
      ]
    }
  },
  mounted() {
    this.queryAllTemplate()
  },
  methods: {
    queryTemplate,
    queryAllTemplate() {
      queryTemplate({ size: 9999, pageNo: 0 }).then(res => {
        this.inspectionTemplate = res.content
      })
    },
    byNameinfo(name) {
      this.byName(name).then(res => {
        if (res.id !== null) {
          this.bydictId(res.id).then(resobject => {
            const _this = this.$refs.form
            _this.inspectionObject = resobject
          })
        }
      })
    },
    toQuery() {
      this.$parent.page = 0
      this.$parent.init()
    },
    add() {
      this.$refs['form'].queryAllEqpt()
      this.$refs['form'].queryAllTemplate()
      this.$refs['form'].getInpectionTools()
      this.$refs['form'].tServiceproviderInfoAll()
      this.$refs['form'].form.startTime = new Date().getTime() + 3600 * 8 * 24 * 1000
      this.$refs['form'].dialog = true
    }
  }
}
</script>
